<?php
/**
 * REMOTEUSER为false，已本地用户为主，登录后，同步登录UCENTER的其它站点
 * @author arlon
 *
 */
class UCenterHookComponent extends Component {
	
	var $appkey = '57326a20-e9cc-461a-8b90-199c9fde689a';
	var $secretKey = 'WYFDXgFMZPFiilBdCWGfqyjSLf1SAsSMG9Pxxz2COLcN';
	
	
	function logout($controller){
		
		//             App::import('Vendor', '',array('file' => 'uc_client'.DS.'client.php'));
		//             if(function_exists('uc_user_synlogout')){
		//                 $synlogout = uc_user_synlogout();
		//             }
		
		if( strpos($_SERVER['HTTP_HOST'],'.135editor.com') !== false ) {
			$url = 'http://www.135plat.com/users/logout?state=script';
		}
		elseif( strpos($_SERVER['HTTP_HOST'],'.135plat.com') !== false ){
			$url = 'http://www.135editor.com/users/logout?state=script';
		}
		return '<script type="text/javascript" src="'.$url.'"></script>';
	}
	
    function loginSuccess($controller,$user) {
        	//App::import('Vendor', '', array('file' => 'uc_client' . DS . 'client.php'));
    	if(defined('UC_APPID')) {
        	$uid = $user['id'];
        	if( $uid ) {
        		$ts = time();
        		$u = Security::rijndael($uid, $this->secretKey, 'encrypt');
        		$u = base64_encode($u);
        		$sign = md5($this->appkey.$this->secretKey.$u.$ts);        		 
        		$params = 'a=appsync&ts='.$ts.'&appkey='.$this->appkey.'&u='.urlencode($u).'&state=script&sign='.$sign;
        		 
	        	if( strpos($_SERVER['HTTP_HOST'],'.135editor.com') !== false ) {
	        		$url = 'http://www.135plat.com/users/login?'.$params;
	        	}
	        	elseif( strpos($_SERVER['HTTP_HOST'],'.135plat.com') !== false ){
	        		$url = 'http://www.135editor.com/users/login?'.$params;
	        	}
	        	return '<script type="text/javascript" src="'.$url.'"></script>';
        	}
        	return null;
    	}
//         if(defined('UC_APPID')) {
    	//		$uid = uc_user_register($user['username'],random_str(10), $user['email'],'','', $controller->request->clientIp());
//         		return $synlogin = uc_user_synlogin($user['id']);
//         }
    }
}
?>
